package org.kjtc.service;

import org.kjtc.entity.BackLog;
import org.kjtc.mapper.ReportFormMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.parsing.ParseState;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2017/12/1 0001.
 */
@Service
public class ReportFormService {

    @Autowired
    private ReportFormMapper reportFormMapper;

    public List<Map<String,Object>> getAllBack(String userId){
        List<Map<String,Object>> lists=reportFormMapper.getAllBack(userId);
        return  lists;
    }

    public List<BackLog> doGetBackLogMsgOne(BackLog backLog){
        List<BackLog> lists=reportFormMapper.doGetBackLogMsgOne(backLog);
        return  lists;
    }
    public List<BackLog> doGetBackLogMsgTwo(BackLog backLog){
        List<BackLog> lists=reportFormMapper.doGetBackLogMsgTwo(backLog);
        return  lists;
    }

    public List getDateNavigations(String txtBeginDate, String txtEndDate){
        if(txtBeginDate=="" || txtBeginDate==null){
            throw new RuntimeException("开始日期不能为空");
        }else if(txtEndDate=="" && txtEndDate==null){
            throw new RuntimeException("结束日期不能为空");
        }
        List list=new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        try {
          cal.setTime(sdf.parse(txtBeginDate));
            String str="";
        for (long d = cal.getTimeInMillis(); d <= sdf.parse(txtEndDate).getTime(); d = get_D_Plaus_1(cal)) {
            list.add(sdf.format(d).toString());
          }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }
    public static long get_D_Plaus_1(Calendar c) {
        c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + 1);
        return c.getTimeInMillis();
    }

}
